//
//  NSObject+XHQMethodSwizzling.m
//  Cafu
//
//  Created by 帝云科技 on 2018/6/4.
//  Copyright © 2018年 diyunkeji. All rights reserved.
//

#import "NSObject+XHQMethodSwizzling.h"
#import <objc/runtime.h>

@implementation NSObject (XHQMethodSwizzling)


+ (void)xhq_swizzlingOriginalSEL:(SEL)originalSEL swizzedSEL:(SEL)swizzedSEL;
{
    Method originalMethod = class_getInstanceMethod([self class], originalSEL);
    Method swizzedMethod = class_getInstanceMethod([self class], swizzedSEL);
    
    BOOL isAddMethod = class_addMethod([self class], originalSEL, method_getImplementation(swizzedMethod), method_getTypeEncoding(swizzedMethod));
    
    if (isAddMethod)
    {
        class_replaceMethod(self, originalSEL, method_getImplementation(swizzedMethod), method_getTypeEncoding(swizzedMethod));
    }
    else
    {
        method_exchangeImplementations(originalMethod, swizzedMethod);
    }
}

@end
